package com.scau.handleException;

import com.scau.dto.CBECReturn;
import com.scau.exception.FileUtilException;
import com.scau.exception.GoodsStockException;
import com.scau.exception.MyException;
import com.scau.exception.OrderItemException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Siaoja
 */
//@ControllerAdvice
public class GlobalExceptionResolver {

    //借买方下订单减少商品库存时，库存不足抛出的异常
    @ExceptionHandler(GoodsStockException.class)
    @ResponseBody
    public CBECReturn handlerGoodsStockException(GoodsStockException gse){
        return CBECReturn.build(gse.getResultCode());
    }
    //FileUtil操作出错
    @ExceptionHandler(FileUtilException.class)
    @ResponseBody
    public CBECReturn handlerGoodsStockException(FileUtilException fue){
        return CBECReturn.build(fue.getResultCode());
    }
    //OrderItem取消订单异常
    @ExceptionHandler(OrderItemException.class)
    @ResponseBody
    public CBECReturn handlerGoodsStockException(OrderItemException oie){
        return CBECReturn.build(oie.getResultCode());
    }


   /* @ExceptionHandler(Exception.class)
    @ResponseBody
    public ApiResult handlerException(Exception e){
        return ApiResult.of(ResultCode.UNKOWN_ERROR);
    }

    @ExceptionHandler(MyException.class)
    @ResponseBody
    public ApiResult handleMyException(MyException myE){
        System.out.println(myE.getCode()+":"+myE.getMsg());
        return ApiResult.of(myE.getResultCode());
    }*/
}
